/******************************************************************************************
 * Import
 ******************************************************************************************/

// module
import Taro, { Component } from '@tarojs/taro'

// project
import { CPage, CContent, CHeader, CFooter, CFloat, CAround, CBetween, CCenter, CRow, CWrap, CLine, CHand, CItemX, CItemY, CText, CLabel, CSvg, CImage, CButton, CColumn } from '../../../library/comp';
import { Base64, Gen, Time, Zip, Session, Storage, Http } from '../../../library/func';
import Icon from '../../../project/style/icon';


/******************************************************************************************
 * Export Class
 ******************************************************************************************/

export default class ProductList extends Component {

	/*------------------------------------------------------------------------------------
	 * 初始化
	 *-----------------------------------------------------------------------------------*/
	constructor(props) {
		super(props);

		/**
		 * state
		 */
		this.state = {
			
		}
	}

	/*------------------------------------------------------------------------------------
	 * 生命周期
	 *-----------------------------------------------------------------------------------*/
	// didMount
	
	/*------------------------------------------------------------------------------------
	 * 事件处理
	 *-----------------------------------------------------------------------------------*/
	// onNavigate
    onNavigate = (url, e)=> {
		wx.navigateTo({
			url: url
		})
	}

	/*------------------------------------------------------------------------------------
	 * 自定义方法
	 *-----------------------------------------------------------------------------------*/

	/*------------------------------------------------------------------------------------
	 * 渲染
	 *-----------------------------------------------------------------------------------*/
	render () {
		return (
			<CColumn mt='220' y='top'>
                {this.props.data.map((item,index) => {
                    return (
                        <CItemX bg='#fff' mb='20' mx='20' ra='16' pa='16' style='width:100%' onClick={ this.onNavigate.bind(this, '/screen/product/detail?id=' + item.id) }>
                            <CHand>
                                <CImage src={'http://image.cdn.hesq.com.cn/rushbuy/product/'+item.object.set_image_small} w='210' h='210'/>
                            </CHand>
                            <CColumn pl='10' y="center" mt="5">
                                <CLine h="70" y="top" size='28'>{item.set_name}</CLine>
                                <CLabel bg='#fee0e0' px='16' py='2' ra='100' size='20' mt='12' ml='10' color='#f92530'>促销价</CLabel>
                                <CLine y='bottom' mt='8' ml='10'>
                                    <CHand size='30'>￥{item.set_price}</CHand>
									{
										this.props.isvip == 1 ?
											(<CItemX y='center'>
												<CHand style="font-size:25rpx;margin-left:30rpx;margin-right:14rpx;">赚</CHand>
												<CHand style="font-size:30rpx;">￥{Math.floor(item.set_price*item.set_commission_percent)/100}</CHand>
											</CItemX>)
											:
											(<CHand style='font-size:30rpx; text-decoration: line-through;color:#999; margin-left:10rpx'>￥{item.set_original_price}</CHand>)
										  
										
									}
                                </CLine>
                                <CLine ml='10' mt="12" size='24' color='#999'>销量 {item.count_sale}</CLine>
                            </CColumn>
                        </CItemX>
                    )
                })}
            </CColumn>
		)
	}
}


